package org.okeoe.gen.base;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Id;
import java.io.Serializable;
import java.util.UUID;

/**
 * Created by luodajie on 2019/1/3.
 */
@Data
public class BaseUUID implements Serializable {
    private static final long serialVersionUID = -6590419805717140795L;
    @Id
    private String id =getUUID();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
        if(StringUtils.isEmpty(id)){
            this.id = getUUID();
        }
    }

    /**
     * 获得一个UUID
     * @return String UUID
     */
    public static String getUUID(){
        String uuid = UUID.randomUUID().toString();
        //去掉“-”符号
        return uuid.replaceAll("-", "");
    }
}
